import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { IBaseEntity } from './IBaseEntity';
import { RedisModule } from '../../config/redis.module';

@Injectable()
export class IBaseService {
  constructor(
    @InjectRepository(IBaseEntity)
    private repository: Repository<IBaseEntity>, // mysql数据库连接工具
  ) {}

  async redisGet(key: string): Promise<any> {
    return RedisModule.redisClient.get(key);
  }

  async redisSet(key: string, value: string): Promise<any> {
    RedisModule.redisClient.set(key, value);
  }
  async redisSetEX(key: string, value: string, seconds: number): Promise<any> {
    return RedisModule.redisClient.setex(key, seconds, value);
  }

  async redisCaptchaGet(key: string): Promise<any> {
    return RedisModule.redisClientCaptcha.get(key);
  }

  async redisCaptchaSet(key: string, value: string): Promise<any> {
    RedisModule.redisClientCaptcha.set(key, value);
  }
  async redisCaptchaSetEX(
    key: string,
    value: string,
    seconds: number,
  ): Promise<any> {
    return RedisModule.redisClientCaptcha.setex(key, seconds, value);
  }
}
